package dzz.Week1;

public class LeetCode58_LengthOfLastWord {

    //字符串遍历
    class Solution {
        public int lengthOfLastWord(String s) {
            int end = s.length() -1;
            while(end >= 0 && s.charAt(end) == ' ') {
                end--;
            }
            if (end < 0) {
                return 0;
            }
            int start = end;
            while(start >= 0 && s.charAt(start) != ' ') {
                start--;
            }
            return end - start;
        }
    }
}
